from get_data.origin_data import *
from get_data.RSJ import RSJ_5D_save, RSJ_10D_save
from get_data.covprice_mid import covprice_save
from get_data.covtend import covtend_save
from get_data.covskew import covskew_save
from get_data.cov_positive_ret_pct import cov_positive_ret_pct_save
from get_data.IVdelta_mid import IVdelta_mid_5D_save, IVdelta_mid_22D_save
from get_data.YTMdelta_mid import YTMdelta_mid_save
from get_data.covpremium_mid import covpremium_mid_save
from get_data.covpremium_modified_mid import covpremium_modified_mid_save
from get_data.stock_bondpremium_mid import stock_bondpremium_mid_save
from get_data.IVnan_pct import IVnan_pct_save

from data_backtest.index_backtest_merge import massive_backtest

from index_judge import massive_drawing

from cul_net_value_drawing import net_value_massive_drawing

from indicator import massive_indictor

# 获取各指标原始数据
def get_basic_data():
    # 指定要创建的目录的路径
    dir_path = "get_data/原始数据"

    try:
        os.mkdir(dir_path)
        print(f'{dir_path}文件夹创建成功')
    except:
        print(f'{dir_path}文件夹已存在, 无需创建')

    RSJ_5D_save()
    RSJ_10D_save()
    covprice_save()
    covtend_save()
    covskew_save()
    cov_positive_ret_pct_save()
    IVdelta_mid_5D_save()
    IVdelta_mid_22D_save()
    YTMdelta_mid_save()
    covpremium_mid_save()
    covpremium_modified_mid_save()
    stock_bondpremium_mid_save()
    IVnan_pct_save()

# 对各指标进行批量回测
def index_backtest():
    dir_path = "因子回测结果"

    try:
        os.mkdir(dir_path)
        print(f'{dir_path}文件夹创建成功')
    except:
        print(f'{dir_path}文件夹已存在, 无需创建')

    df_basic = pd.read_csv('get_data/原始数据/RSJ_5D.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='RSJ_5D回测')

    df_basic = pd.read_csv('get_data/原始数据/RSJ_10D.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='RSJ_10D回测')

    df_basic = pd.read_csv('get_data/原始数据/cov_+ret_pct_5D.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='cov_+ret_pct_5D回测')

    df_basic = pd.read_csv('get_data/原始数据/covprice_mid.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='covprice_mid回测')

    df_basic = pd.read_csv('get_data/原始数据/covtend.csv')
    massive_backtest(df_basic=df_basic, flag=0, filename='covtend回测')

    df_basic = pd.read_csv('get_data/原始数据/covskew.csv')
    massive_backtest(df_basic=df_basic, flag=0, filename='covskew回测')

    df_basic = pd.read_csv('get_data/原始数据/IVdelta_mid_5D.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='IVdelta_mid_5D回测')

    df_basic = pd.read_csv('get_data/原始数据/IVdelta_mid_22D.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='IVdelta_mid_22D回测')

    df_basic = pd.read_csv('get_data/原始数据/YTMdelta_mid.csv')
    massive_backtest(df_basic=df_basic, flag=0, filename='YTMdelta_mid回测')

    df_basic = pd.read_csv('get_data/原始数据/covpremium_mid.csv')
    massive_backtest(df_basic=df_basic, flag=0, filename='covpremium_mid回测')

    df_basic = pd.read_csv('get_data/原始数据/covpremium_modified_mid.csv')
    massive_backtest(df_basic=df_basic, flag=0, filename='covpremium_modified_mid回测')

    df_basic = pd.read_csv('get_data/原始数据/stock_bondpremium_mid.csv')
    massive_backtest(df_basic=df_basic, flag=1, filename='stock_bondpremium_mid回测')

    df_basic = pd.read_csv('get_data/原始数据/IVnan_pct.csv')
    massive_backtest(df_basic=df_basic, flag=0, filename='IVnan_pct回测')

# 对各指标形态进行判断
def index_shape():
    dir_path = "因子形态判断图"

    try:
        os.mkdir(dir_path)
        print(f'{dir_path}文件夹创建成功')
    except:
        print(f'{dir_path}文件夹已存在, 无需创建')

    massive_drawing()

# 绘制因子净值对比图
def net_value_compare():
    dir_path = "因子净值对比图"

    try:
        os.mkdir(dir_path)
        print(f'{dir_path}文件夹创建成功')
    except:
        print(f'{dir_path}文件夹已存在, 无需创建')

    net_value_massive_drawing()

# 计算评价指标
def indictor_cal():
    dir_path = "因子评价指标"

    try:
        os.mkdir(dir_path)
        print(f'{dir_path}文件夹创建成功')
    except:
        print(f'{dir_path}文件夹已存在, 无需创建')

    massive_indictor()

if __name__ == '__main__':
    get_basic_data()
    index_backtest()
    index_shape()
    net_value_compare()
    indictor_cal()